package com.wyh.controller.groupOne.customer;

import com.wyh.common.enums.ResultCodeEnum;
import com.wyh.common.result.Result;
import com.wyh.domain.vo.groupOne.customer.InvoiceconfigurationVO;
import com.wyh.service.groupOne.customer.MasterDataInvoiceconfigurationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "开票配置API")
@RestController
@RequestMapping("/invoiceconfiguration")
public class InvoiceconfigurationController {

    @Autowired
    private MasterDataInvoiceconfigurationService masterDataInvoiceconfigurationService;

    /**
     * 查询开票配置
     * @param id
     * @return
     */
    @ApiOperation("根据客户id查询开票配置")
    @ApiImplicitParam(name = "id",value = "客户id",required = true)
    @GetMapping("selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        InvoiceconfigurationVO invoiceconfigurationVO = masterDataInvoiceconfigurationService.selectByCustomerId(id);
        return Result.success(invoiceconfigurationVO);
    }

    /**
     * 添加开票配置
     * @param invoiceconfigurationVO
     * @return
     */
    @ApiOperation("添加开票配置")
    @PostMapping("add")
    public Result insert(@RequestBody InvoiceconfigurationVO invoiceconfigurationVO) {
        if (invoiceconfigurationVO.getUserid() == null) {
            return Result.error(ResultCodeEnum.OPERATION_AUTHORITY_ERROR);
        }
        masterDataInvoiceconfigurationService.insert(invoiceconfigurationVO);
        return Result.success();
    }

    /**
     * 修改开票配置
     * @param invoiceconfigurationVO
     * @return
     */
    @ApiOperation("根据自身id修改开票配置")
    @PostMapping("update")
    public Result update(@RequestBody InvoiceconfigurationVO invoiceconfigurationVO) {
        if (invoiceconfigurationVO.getUserid() == null) {
            return Result.error(ResultCodeEnum.OPERATION_AUTHORITY_ERROR);
        }
        masterDataInvoiceconfigurationService.update(invoiceconfigurationVO);
        return Result.success();
    }
}
